#include "sales.h"
#include <iostream>

using namespace SALES;

void SALES::setSales(Sales& s, const double ar[], int n)
{
	int len = n < QUARTERS ? n : QUARTERS;
	double sum = 0.0;
	for (int i = 0; i < len; i++)
	{
		s.sales[i] = ar[i];
		sum += s.sales[i];
	}
	s.max = s.sales[0];
	s.min = s.sales[0];

	for (int i = 1; i < len; i++)
	{
		if (s.max < s.sales[i])s.max = s.sales[i];
		if (s.min > s.sales[i])s.min = s.sales[i];
	}
	s.average = sum / len;
}

void SALES::setSales(Sales& s)
{
	double sum = 0.0;
	for (int i = 0; i < QUARTERS; i++)
	{
		std::cin >> s.sales[i];
		sum += s.sales[i];
	}
	s.max = s.min = s.sales[0];
	for (int i = 1; i < QUARTERS; i++)
	{
		if (s.max < s.sales[i])s.max = s.sales[i];
		if (s.min > s.sales[i])s.min = s.sales[i];
	}
	s.average = sum / QUARTERS;
}

void SALES::showSales(const Sales& s)
{
	for (int i = 0; i < QUARTERS; i++)
	{
		std::cout << s.sales[i] << " ";
	}
	std::cout << std::endl;
	std::cout << "max:" << s.max << std::endl;
	std::cout << "min:" << s.min << std::endl;
	std::cout << "average:" << s.average << std::endl;
}


